<template>
    <div class="article_stg">
        <h1>修改文章</h1>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="文章标题" prop="title">
                <el-input v-model="ruleForm.title"></el-input>
            </el-form-item>
            <el-form-item label="推荐" prop="recommend">
                <el-radio-group v-model="radio">
                    <el-radio :label="1">5星</el-radio>
                    <el-radio :label="2">4星</el-radio>
                    <el-radio :label="3">3星</el-radio>
                    <el-radio :label="4">2星</el-radio>
                    <el-radio :label="5">1星</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="简介" prop="brief">
                <el-input v-model="ruleForm.brief"></el-input>
            </el-form-item>
           <el-form-item label="展示方式" prop="show">
               <el-radio-group v-model="rdio">
                    <el-radio :label="1">单图</el-radio>
                    <el-radio :label="2">三张图</el-radio>
                </el-radio-group>
                <span>展示类型选定后，只能替换图片</span>
                <el-upload
                  class="upload-demo"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :on-change="handleChange"
                  :file-list="fileList">
                  <el-button size="small" type="primary">点击上传</el-button>
                  <el-button size="small" type="success">上传服务器</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，每次只能上传一张,最大不超过5mb</div>
                </el-upload>
            </el-form-item>
            <el-form-item label="职位描述" prop="views">
                <el-input type="textarea" v-model="ruleForm.desc"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import config from '@/assets/js/config.js'
  export default {
      created() {
          var id = this.$route.params.id;
          console.log(id)
          this.$require.get(config.newsChange,{
            params: {
              id:id
            }
        }).then((res) => {
            console.log("0000",res)
            this.ruleForm = res.data.data;
        }).catch(function (err) {
            console.log("出错了")
        })
      },
    data() {
      return {
        ruleForm: {},
        radio: 1,
        rdio: 1,
        rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          show: [
            { required: true, message: '请选择图片', trigger: 'blur' }
          ],
          Introduction: [
            { required: true, message: '请选择简介', trigger: 'blur' }
          ],
          desc: [
            { required: true, message: '请填写描述', trigger: 'blur' }
          ]
        },
        fileList: [],
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      handleChange(file, fileList) {
        this.fileList = fileList.slice(-3);
      }
    }
  }
</script>

<style lang="scss" scoped>
    .article_stg{
        padding-top: 20px;
        padding-left: 20px;
        padding-right: 20%;
        h1{
            margin-bottom: 20px;
        }
        span{
            display: inline-block;
            margin-left: 40px;
        }
    }
</style>
